package project.parser.ast.exps.op.binary;

import project.environments.DynamicEnv;
import project.environments.StaticEnv;
import project.environments.Value;
import project.parser.ast.exps.Exp;
import project.parser.ast.types.PrimType;
import project.parser.ast.types.Type;
import project.parser.ast.util.EvalUtil;
import project.parser.ast.util.TypecheckUtil;
import project.parser.ast.values.IntValue;
import project.parser.tokenizer.TokenType;

public class Add extends BinaryOp {
	public Add(Exp left, Exp right) {
		super(left, right);
	}

	@Override
	protected String opToString() {
		return TokenType.ADD.toString();
	}

	@Override
	public Type typecheck(StaticEnv senv) {
		return TypecheckUtil.checkType(senv, PrimType.NUMBER_TYPE, left, right);
	}

	@Override
	public Value evaluate(DynamicEnv denv) {
		int[] args = EvalUtil.evalIntArgs(denv, left, right);
		return new IntValue(args[0] + args[1]);
	}
}
